package proxy

import (
	"github.com/xelabs/go-mysqlstack/driver"
	"github.com/xelabs/go-mysqlstack/sqlparser/depends/query"
	"github.com/xelabs/go-mysqlstack/sqlparser/depends/sqltypes"
	"github.com/xuender/oils/logs"
)

type BaseHandler struct{}

func (p *BaseHandler) ServerVersion() string {
	logs.Debug("ServerVersion()")

	return "5.5.62-0ubuntu0.14.04.1-log"
}

func (p *BaseHandler) SetServerVersion() {
	logs.Debug("SetServerVersion()")
}

func (p *BaseHandler) NewSession(session *driver.Session) {
	logs.Debugw("NewSession", "id", session.ID())
}

func (p *BaseHandler) SessionInc(session *driver.Session) {
	logs.Debugw("SessionInc", "id", session.ID())
}

func (p *BaseHandler) SessionDec(session *driver.Session) {
	logs.Debugw("SessionDec", "id", session.ID())
}

func (p *BaseHandler) SessionClosed(session *driver.Session) {
	logs.Debugw("SessionClosed", "id", session.ID())
}

func (p *BaseHandler) SessionCheck(session *driver.Session) error {
	logs.Debugw("SessionCheck", "id", session.ID())

	return nil
}

func (p *BaseHandler) AuthCheck(session *driver.Session) error {
	logs.Debugw("AuthCheck",
		"id", session.ID(),
		"User", session.User(),
		"Salt", session.Salt(),
		"Addr", session.Addr(),
		"schema", session.Schema(),
		"scramble", session.Scramble(),
		"native", NativePassword("123", session.Salt()),
	)

	return nil
}

func (p *BaseHandler) ComInitDB(session *driver.Session, database string) error {
	logs.Debugw("ComInitDB", "id", session.ID(), "database", database)

	return nil
}

func (p *BaseHandler) ComQuery(
	session *driver.Session,
	query string,
	bindVariables map[string]*query.BindVariable,
	callback func(*sqltypes.Result) error,
) error {
	logs.Debugw("ComQuery", "id", session.ID(), "query", query)

	return nil
}
